﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.GeneralClass;
using TcpLabCommon;
using System.Windows.Forms;
using System.Drawing;
using TCPIPControl.StructHelper;
using Common.DBOper;
using System.Diagnostics;

namespace Common
{
    public static class Mdl_Class
    {

        public static  string FilePath="";

        public static string connectString = "Data Source=." +
                        ";Initial Catalog=" + "TRW_Reflash_DB" +
                        ";Persist Security Info=True;User ID=" + "sa" +
                        ";Password=" + @"1234";

        public static string AccessPassWord = "1234";

        public static Dictionary<string, string> testTopath = new Dictionary<string, string>();

        private static WriteLog writeLog = null;

        public static int frmMainState = 0;//0代表主窗体关闭，1代表主窗体打开

        public static int nowupdatecount = 0;//当前更新数据库的条数
        public static int sumcount = 0;//总条数

       
        public static string ServerIP = "127.0.0.1";

        public static int ServerPort = 3001;

        public static int acqId=0;

        public static string acqName = "";

        public static int projectId = 0;

        public static int taskId = 0;

        public static Cls_Project _Project=null;

        public static bool IsSaveData=true;//是否存储数据

        public static bool IsErrMessage = false;//是否提示报警信息

        public static string DatePath = "";//数据存储路劲

        public static double ErrValue = 0.0;//磁盘空间报警值

        public static bool IsSaveFFTAmp = true;//是否存储加速度频谱原始数据

        public static bool IsCloseWait = false;//是否关闭等待窗口

        public static PrjSet prjset = null;
        public static List<SpeedToTime> speedtotimelist = new List<SpeedToTime>();//时间与转速的对应关系

        public static int speed_channel = 0;
        public static int[] speed_channellsit1 = new int[] {1,2,17,18,19,20,21,22,23,24 };
        public static int[] speed_channellsit2 = new int[] { 7, 8, 25, 26, 27, 28, 29, 30, 31,32 };

        public static Dictionary<int, AccelerationDB> speedAcqlist = new Dictionary<int,AccelerationDB>();
        public static WriteLog WriteLog
        {
            get
            {
                if (writeLog == null)
                {
                    writeLog = new WriteLog(Systemset.LogPath);
                }
                return writeLog;
            }
        }



        private static Cls_SystemSet systemset = null;

        public static Cls_SystemSet Systemset
        {
            get
            {
                if (systemset == null)
                {
                    systemset = new Cls_SystemSet();
                }
                return systemset;
            }
        }

        private static MyDb mydb = null;

        public static MyDb Mydb
        {
            get { 
                if(mydb==null)
                {
                    mydb = new MyDb(Mdl_Class.Systemset.DBConnectionString());
                }
                return mydb;
            }
        }

        private static MyDb delMydb = null;
        public static MyDb DelMydb
        {
            get
            {
                if (delMydb == null)
                {
                    delMydb = new MyDb(Mdl_Class.Systemset.DBConnectionString());
                }
                return delMydb;
            }
        }


        private static MyDb insertMydb = null;
        public static MyDb InsertMydb
        {
            get
            {
                if (insertMydb == null)
                {
                    insertMydb = new MyDb(Mdl_Class.Systemset.DBConnectionString());
                }
                return insertMydb;
            }
        }

        private static MyDb mydb_other = null;

        public static MyDb Mydb_other
        {
            get
            {
                if (mydb_other == null)
                {
                    mydb_other = new MyDb(Mdl_Class.Systemset.DBConnectionStringOther());
                }
                return mydb_other;
            }
        }
        private static User user = null;

        public static User User
        {
            get {
                if (user == null)
                {
                    user = new User();
                }

                return user;
            }

        }
        private static OperateUser operateuser = null;

        public static OperateUser Operateuser
        {
            get
            {
                if (operateuser == null)
                {
                    operateuser = new OperateUser();
                }
                return operateuser;
            }

        }


        private static OperateAccelerationDB operateAccelerationDB = null;

        public static OperateAccelerationDB OperateAccelerationDB
        {
            get
            {
                if (operateAccelerationDB == null)
                {
                    operateAccelerationDB = new OperateAccelerationDB();
                }
                return operateAccelerationDB;
            }

        }


        private static Common.GeneralClass.OperateChannel operatechannel = null;

        public static Common.GeneralClass.OperateChannel Operatechannel
        {
            get
            {
                if (operatechannel == null)
                {
                    operatechannel = new Common.GeneralClass.OperateChannel();
                }
                return operatechannel;
            }
        }


        private static OperateACQDB operateacqdb = null;

        public static OperateACQDB Operateacqdb
        {
            get
            {
                if (operateacqdb == null)
                {
                    operateacqdb = new OperateACQDB();
                }
                return operateacqdb;
            }
        }


        private static OperateProject operateproject = null;

        public static OperateProject Operateproject
        {
            get
            {
                if (operateproject == null)
                {
                    operateproject = new OperateProject();
                }
                return operateproject;
            }
        }


        private static OperateTask operatetask = null;

        public static OperateTask Operatetask
        {
            get
            {
                if (operatetask== null)
                {
                    operatetask = new OperateTask();
                }
                return operatetask;
            }
        }



        private static OperateBlackBoxDB operateBlackBoxDB = null;

        public static OperateBlackBoxDB OperateBlackBoxddb
        {
            get
            {
                if (operateBlackBoxDB == null)
                {
                    operateBlackBoxDB = new OperateBlackBoxDB();
                }
                return operateBlackBoxDB;
            }
        }


        public static string ACQSet = "";
        public static string ChannelSet = "";

        public static TCPIPControl.StructHelper.ACQParametersConfig acqParametersConfig = new TCPIPControl.StructHelper.ACQParametersConfig ();
        public static ACQParametersConfig acqparmeter = new ACQParametersConfig();
        public static Object accdata = null;
        public static DisplacementData displacementData = new DisplacementData();
        public static SlowSignal slowSignal = new SlowSignal();
        public static SpeedData speedData = new SpeedData();
        public static SamplingConfig SamplingConfig = new SamplingConfig();
        public static MachineTime machineTime = new MachineTime();

        public static List<object> accdatalist = new List<object>();
        public static List<DisplacementData> displacementDatalist = new List<DisplacementData>();
        public static List<SpeedData> speedDatalist = new List<SpeedData>();
        public static List<SlowSignal> slowSignallist = new List<SlowSignal>();
        public static List<SamplingConfig> SamplingConfiglist = new List<SamplingConfig>();

        public static Dictionary<ushort, int> ChannelIdToSpeedId = new Dictionary<ushort, int>();
        public static float[] rpm_values = new float[6];

        public static long RpmId = 0;

        public static bool IsQuitProgram=true;

        //跟踪转速
        public static string trackSpeed(DataPacket dpk,Cls_Channel acqchannel) 
        {
            string speed = "0";
            switch (acqchannel.SpeedId)
            {
                case "1":
                    speed = Math.Round(dpk.Rpm1,0).ToString();
                    break;
                case "2":
                    speed = Math.Round(dpk.Rpm2, 0).ToString();
                    break;
                case "3":
                    speed = Math.Round(dpk.Rpm3, 0).ToString();
                    break;
                case "4":
                    speed = Math.Round(dpk.Rpm4, 0).ToString();
                    break;
                case "5":
                    speed = Math.Round(dpk.Rpm4, 0).ToString();
                    break;
                case "6":
                    speed = Math.Round(dpk.Rpm4, 0).ToString();
                    break;
                default:
                    break;
            }
      
            return speed;
        }

        /// <summary>
        /// 查询通道跟踪的转速
        /// </summary>
        /// <param name="channelid"></param>
        /// <returns></returns>
        public static int GetSpeedId(int channelid)
        {
            int cardid = channelid / prjset.channelCount;
            int channlid = channelid % prjset.channelCount;
            int speedid = Convert.ToInt32(_Project.ACQUnitList.ACQUnitList[0].ACQCardList.ACQCards[cardid].ChannelList.Channels[channlid].SpeedId);
            return speedid;
        }


        public static string GetFieldName(string fieldName) 
        {
            string fieldname = "";
            switch (fieldName)
            {
                case "Rpm1":
                    fieldname = "转速1";
                    break;
                case "Rpm2":
                    fieldname = "转速2";
                    break;
                case "Rpm3":
                    fieldname = "转速3";
                    break;
                case "Rpm4":
                    fieldname = "转速4";
                    break;
                case "PK2PK":
                    fieldname = "峰峰值";
                    break;
                case "GapVoltage":
                    fieldname = "间隙电压";
                    break;
                case "RoomSquareValue":
                    fieldname = "平方根值";
                    break;
                case "OneMultiplierAmp":
                    fieldname = "一倍频幅值";
                    break;
                case "OneMultiplierPhase":
                    fieldname = "一倍频相位";
                    break;
                case "TWOMultiplierAmp":
                    fieldname = "二倍频幅值";
                    break;
                case "TWOMultiplierPhase":
                    fieldname = "二倍频相位";
                    break;
                case "HalfMultiplierAmp":
                    fieldname = "半频幅值";
                    break;
                case "FrequencyRange1":
                    fieldname = "可选频段1";
                    break;
                case "FrequencyRange2":
                    fieldname = "可选频段2";
                    break;
                case "FrequencyRange3":
                    fieldname = "可选频段3";
                    break;
                case "SlowSignal":
                    fieldname = "慢信号";
                    break;
                default:
                    break;
            }

            return fieldname;
        }
        
        //显示值的颜色
        public static void DisplayYelloworRed(string fieldname, Label lb,PrjSet CurrentPrjSet, int acqid, int cardid, int channelno)
        {
            float readValue = 0;

            int channelid = cardid * CurrentPrjSet.channelCount + channelno;
            switch (fieldname)
            {
                case "可选频段1":
                    int FrequencyRange1_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange1")[0]);
                    int FrequencyRange1_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange1")[1]);
                    int FrequencyRange1_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange1")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].FreOption1,2));
                    lb.Text = readValue.ToString();
                    if (FrequencyRange1_isuser == 1)
                    {
                        if (readValue >= FrequencyRange1_yellowvalue && readValue < FrequencyRange1_redvalue)
                        {
                       
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= FrequencyRange1_redvalue)
                        {
           
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "可选频段2":
                    int FrequencyRange2_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange2")[0]);
                    int FrequencyRange2_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange2")[1]);
                    int FrequencyRange2_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange2")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].FreOption2, 2));
                    lb.Text = readValue.ToString();
                    if (FrequencyRange2_isuser == 1)
                    {
                        if (readValue >= FrequencyRange2_yellowvalue && readValue < FrequencyRange2_redvalue)
                        {
                      
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= FrequencyRange2_redvalue)
                        {
                  
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "可选频段3":
                    int FrequencyRange3_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange3")[0]);
                    int FrequencyRange3_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange3")[1]);
                    int FrequencyRange3_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("FrequencyRange3")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].FreOption3, 2));
                    lb.Text = readValue.ToString();
                    if (FrequencyRange3_isuser == 1)
                    {
                        if (readValue >= FrequencyRange3_yellowvalue && readValue < FrequencyRange3_redvalue)
                        {
                         
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= FrequencyRange3_redvalue)
                        {
                     
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "半频幅值":
                    int HalfMultiplierAmp_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("HalfMultiplierAmp")[0]);
                    int HalfMultiplierAmp_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("HalfMultiplierAmp")[1]);
                    int HalfMultiplierAmp_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("HalfMultiplierAmp")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].HalfMultiplierAmp, 2));
                    lb.Text = readValue.ToString();
                    if (HalfMultiplierAmp_isuser == 1)
                    {
                        if (readValue >= HalfMultiplierAmp_yellowvalue && readValue < HalfMultiplierAmp_redvalue)
                        {
                        
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= HalfMultiplierAmp_redvalue)
                        {
                
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "一倍频幅值":
                    int OneMultiplierAmp_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("OneMultiplierAmp")[0]);
                    int OneMultiplierAmp_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("OneMultiplierAmp")[1]);
                    int OneMultiplierAmp_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("OneMultiplierAmp")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].OneMultiplierAmp, 2));
                    lb.Text = readValue.ToString();
                    if (OneMultiplierAmp_isuser == 1)
                    {
                        if (readValue >= OneMultiplierAmp_yellowvalue && readValue < OneMultiplierAmp_redvalue)
                        {
                     
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= OneMultiplierAmp_redvalue)
                        {
                       
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "一倍频相位":
                    int OneMultiplierPhase_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("OneMultiplierPhase")[0]);
                    int OneMultiplierPhase_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("OneMultiplierPhase")[1]);
                    int OneMultiplierPhase_isuser= Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("OneMultiplierPhase")[1]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].OneMultiplierPhase, 2));
                    lb.Text = readValue.ToString();
                    if (OneMultiplierPhase_isuser == 1)
                    {
                        if (readValue >= OneMultiplierPhase_yellowvalue && readValue < OneMultiplierPhase_redvalue)
                        {
                  
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= OneMultiplierPhase_redvalue)
                        {
                
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;

                case "二倍频幅值":
                    int TWOMultiplierAmp_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("TWOMultiplierAmp")[0]);
                    int TWOMultiplierAmp_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("TWOMultiplierAmp")[1]);
                    int TWOMultiplierAmp_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("TWOMultiplierAmp")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].TWOMultiplierAmp, 2));
                    lb.Text = readValue.ToString();
                    if (TWOMultiplierAmp_isuser==1)
                    {
                        if (readValue >= TWOMultiplierAmp_yellowvalue && readValue < TWOMultiplierAmp_redvalue)
                        {
                         
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= TWOMultiplierAmp_redvalue)
                        {
                
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "二倍频相位":
                    int TWOMultiplierPhase_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("TWOMultiplierPhase")[0]);
                    int TWOMultiplierPhase_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("TWOMultiplierPhase")[1]);
                    int TWOMultiplierPhase_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("TWOMultiplierPhase")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].TWOMultiplierPhase, 2));
                    lb.Text = readValue.ToString();
                    if (TWOMultiplierPhase_isuser == 1)
                    {
                        if (readValue >= TWOMultiplierPhase_yellowvalue && readValue < TWOMultiplierPhase_redvalue)
                        {
                           
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= TWOMultiplierPhase_redvalue)
                        {
              
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "峰峰值":
                    int PK2PK_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("PK2PK")[0]);
                    int PK2PK_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("PK2PK")[1]);
                    int PK2PK_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("PK2PK")[2]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].PK2PK, 2));
                    lb.Text = readValue.ToString();
                    if (PK2PK_isuser==1)
                    {
                        if (readValue >= PK2PK_yellowvalue && readValue < PK2PK_redvalue)
                        {
                           
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= PK2PK_redvalue)
                        {
                      
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                case "均方根值":
                    int RoomSquareValue_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("RoomSquareValue")[0]);
                    int RoomSquareValue_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("RoomSquareValue")[1]);
                    int RoomSquareValue_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("RoomSquareValue")[1]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].RoomSquareValue, 2));
                    lb.Text = readValue.ToString();
                    if (RoomSquareValue_isuser == 1)
                    {
                        if (readValue >= RoomSquareValue_yellowvalue && readValue < RoomSquareValue_redvalue)
                        {
                          
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= RoomSquareValue_redvalue)
                        {
                       
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;

                case "间隙电压":
                    int GapVoltage_yellowvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("GapVoltage")[0]);
                    int GapVoltage_redvalue = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("GapVoltage")[1]);
                    int GapVoltage_isuser = Convert.ToInt16(_Project.ACQUnitList.ACQUnitList[acqid].ACQCardList.ACQCards[cardid].ChannelList.Channels[channelno].ChannelPropertyList.GetChannelProperty("GapVoltage")[1]);
                    readValue = Convert.ToSingle(Math.Round(Mdl_Class.displacementData.CHDisData[channelid].GapVoltage, 2));
                    lb.Text = readValue.ToString();
                    if (GapVoltage_isuser == 1)
                    {
                        if (readValue >= GapVoltage_yellowvalue && readValue < GapVoltage_redvalue)
                        {
                      
                            lb.ForeColor = Color.Orange;
                        }
                        else if (readValue >= GapVoltage_redvalue)
                        {
                      
                            lb.ForeColor = Color.Red;
                        }
                        else
                        {
                            lb.ForeColor = Color.Green;
                        }
                    }
                    else 
                    {
                        lb.ForeColor = Color.Green;
                    }
                    break;
                default:
                    break;
            }

        }


        public static string ViewACQ = "(SELECT Id, acqId, acqName, dataPaket, insertTime, projectId " +
           " FROM  (SELECT Id, acqId, acqName, dataPaket, insertTime, projectId " +
              " FROM   dbo.T_B_ACQ_Hour " +
               "UNION ALL " +
               "SELECT Id, acqId, acqName, dataPaket, insertTime, projectId " +
               "FROM  dbo.T_B_ACQ_Day " +
               "WHERE (insertTime NOT IN " +
               "(SELECT insertTime " +
               "FROM   dbo.T_B_ACQ_Hour AS T_B_ACQ_Hour_4)) " +
               "UNION ALL " +
               "SELECT Id, acqId, acqName, dataPaket, insertTime, projectId " +
               "FROM  dbo.T_B_ACQ_Week " +
               "WHERE (insertTime NOT IN " +
               "(SELECT insertTime " +
               "FROM dbo.T_B_ACQ_Hour AS T_B_ACQ_Hour_3 " +
               "UNION ALL " +
               "SELECT insertTime " +
               "FROM  dbo.T_B_ACQ_Day AS T_B_ACQ_Day_3)) " +
               "UNION ALL " +
               "SELECT Id, acqId, acqName, dataPaket, insertTime, projectId " +
               "FROM  dbo.T_B_ACQ_Month " +
               "WHERE (insertTime NOT IN " +
               "(SELECT insertTime " +
               "FROM   dbo.T_B_ACQ_Hour AS T_B_ACQ_Hour_2 " +
               "UNION ALL " +
               "SELECT insertTime " +
               "FROM  dbo.T_B_ACQ_Day AS T_B_ACQ_Day_2 " +
               "UNION ALL " +
               "SELECT insertTime " +
               "FROM  dbo.T_B_ACQ_Week AS T_B_ACQ_Week_2)) " +
               "UNION ALL " +
               "SELECT Id, acqId, acqName, dataPaket, insertTime, projectId " +
               "FROM  dbo.T_B_ACQ_Year " +
               "WHERE (insertTime NOT IN " +
               "(SELECT insertTime " +
               "FROM   dbo.T_B_ACQ_Hour AS T_B_ACQ_Hour_1 " +
               "UNION ALL " +
               "SELECT insertTime " +
               "FROM  dbo.T_B_ACQ_Day AS T_B_ACQ_Day_1 " +
               "UNION ALL " +
               "SELECT insertTime " +
               "FROM  dbo.T_B_ACQ_Week AS T_B_ACQ_Week_1 " +
               "UNION ALL " +
               "SELECT insertTime " +
               "FROM  dbo.T_B_ACQ_Month AS T_B_ACQ_Month_1))) AS tb1)as tb_acq";


            public static Dictionary<long, AccDataInfo> accdblist = new Dictionary<long, AccDataInfo>();//振动加速度数据缓存


        /// <summary>
        /// 返回时间与转速对应关系
        /// </summary>
        /// <param name="dt1">时间</param>
        /// <param name="speedtotime">加速度数据列表</param>
        /// <returns></returns>
            public static SpeedToTime GetTimeToSpeed(DateTime dt1, List<SpeedToTime> speedtotime)
            {
                double mintime = 1000000;
                SpeedToTime sp = new SpeedToTime();
                for (int i = 0; i < speedtotime.Count; i++)
                {
                    TimeSpan d3 = dt1.Subtract(speedtotime[i].insertTime[i]);


                    if (Math.Abs(d3.TotalSeconds) < mintime)
                    {
                        mintime = Math.Abs(d3.TotalSeconds);
                        sp = speedtotime[i];
                    }
                }
                if (mintime > 60)
                {
                    sp = new SpeedToTime();
                    sp.insertTime[0] = dt1;

                    return sp;
                }
                else
                {

                    return sp;
                }
            }
            /// <summary>
            /// 移除全部缓存
            /// </summary>
            public static void RemoveAllCache()
            {
         
            }

            public static bool IsAddPoint = false;//是否应许往界面中添加数据

            public static Dictionary<string,Dictionary<int, DisplacementDataInfo>> AcqDataList = new Dictionary<string,Dictionary<int, DisplacementDataInfo>>();//往界面中添加数据
           
           public static Dictionary<int, DisplacementDataInfo> IniAcqData = new Dictionary<int, DisplacementDataInfo> ();//初始数据位置

            public static Dictionary<int, float> Init_pointlist = new Dictionary<int, float>();//通道初始位置值
            public static Dictionary<int, string> Init_pointName_list = new Dictionary<int, string>();//通道初始位置值
            public static Dictionary<int, Cls_Channel> Init_pointChannle_list = new Dictionary<int, Cls_Channel>();//通道初始位置值

            public static int lvbo_select = 0;
            public static int xs_select = 3;


            public static Dictionary<long, AccDataInfo> Init_AccelerationDB = new Dictionary<long, AccDataInfo>();//频谱数据点

            public static Dictionary<long, string> NowChannelNameList = new Dictionary<long,string> ();

            public static string NowChannelName = "";

            public static string SendInstruct="";

            public static DateTime startTime = DateTime.Now;


            public static string TestName = "";
            public static long TestId = 0;
            public static int SampFreq = 0;//采样频率
            public static int SampFreq_index = 0;//采样频率
            public static int LineNO = 0;//线数
            public static int AverageNO= 0;//平均次数
            public static int AverageMod = 0;//平均方式
            public static int WindowFunction = 0;//计算窗函数


            public static string AverageMod_Name = "";//平均方式
            public static string WindowFunction_Name = "";//计算窗函数



            public static Dictionary<string, int> sectionNameTosectionId = new Dictionary<string, int>();

            public static Dictionary<string, Cls_Test> testNameTotest = new Dictionary<string, Cls_Test>();


            public static int NowStectionId = 0;
            public static string NowStectionName ="";
            public static int TestProgress = 0;
            public static int NowRunTestStectionId = 0;

            public static Dictionary<byte, List<Cls_Data>> ChannelDataList = new Dictionary<byte, List<Cls_Data>>();

            public static Dictionary<byte, int> ChannelDataCount = new Dictionary<byte, int>();

            public static Dictionary<byte, List<float>> ChannelOldDataList = new Dictionary<byte, List<float>>();

            public static bool LowerMachineIsConnect = false;
            public static Stopwatch ConnectTime = new Stopwatch();


            public static int OnLineChannelId = 0;


            public static List<Object> onlinchannelData = new List<object>();

            public static int TestModel = 0;//无模式 1:测试模式 2运行模式


            public static int Test1_channel = 0;
            public static int Test2_channel = 0;
            public static int Test3_channel = 0;
            public static int Test4_channel = 0;

            public static List<Object> Test1_Data = new List<object>();
            public static List<Object> Test2_Data = new List<object>();
            public static List<Object> Test3_Data = new List<object>();
            public static List<Object> Test4_Data = new List<object>();
    }
}
